package com.ruoyi.web.controller.project;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.Item;
import com.ruoyi.system.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/project/item")
public class ItemController {
    @Autowired
    private IItemService itemService;

    @GetMapping("/{itemId}")
    public AjaxResult getItem(@PathVariable String itemId) {
        Item item = itemService.selectItemById(itemId);
        return AjaxResult.success(item);
    }

    @GetMapping("/list")
    public AjaxResult listItems(Item item) {
        List<Item> list = itemService.selectItemList(item);
        return AjaxResult.success(list);
    }

    @PostMapping
    public AjaxResult addItem(@RequestBody Item item) {
        int result = itemService.insertItem(item);
        return result > 0 ? AjaxResult.success() : AjaxResult.error();
    }

    @PutMapping
    public AjaxResult updateItem(@RequestBody Item item) {
        int result = itemService.updateItem(item);
        return result > 0 ? AjaxResult.success() : AjaxResult.error();
    }

    @DeleteMapping("/{itemId}")
    public AjaxResult deleteItem(@PathVariable String itemId) {
        int result = itemService.deleteItemById(itemId);
        return result > 0 ? AjaxResult.success() : AjaxResult.error();
    }

    @DeleteMapping("/batch")
    public AjaxResult deleteItems(@RequestBody String[] itemIds) {
        int result = itemService.deleteItemByIds(itemIds);
        return result > 0 ? AjaxResult.success() : AjaxResult.error();
    }
} 